/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import Edf.EDFRead;
import Edf.Reader;
import java.io.File;

/**
 * Contains the original data of an opened EDF file.
 * @author Cliff Laschet
 */
public class Buffer {
    private static double[][] data;
    private static File curFile;
    private static int currentSampleSize;
    private static double recordDuration;
    private static double numberOfSamples;
    private static double timePerSample;

    /**
     * Reads the given sample size from every signal.
     * @param file
     * @param sampleSize
     */
    public static void readFile(File file, int sampleSize){
        curFile = file;
        //Use the old reader to get the time between samples.
        EDFRead read = new EDFRead(file.getAbsolutePath());
        double[] info = read.getData();
        recordDuration = info[0]*60*1000;
        numberOfSamples = info[1];
        timePerSample = recordDuration / getNumberOfSamples();

        //Use the new reader for actually reading the value of samples.
        Reader.openEDFFile(file.getAbsolutePath());
        currentSampleSize = sampleSize;
        data = new double[5][sampleSize];
        for(int signal = 0; signal < 5; signal++){
            data[signal] = Reader.readSamples(signal, sampleSize);
        }
    }

    /**
     * Returns the read smaples of a specific given signal.
     * @param signal
     * @return
     */
    public static double[] getSignalData(int signal){
        return data[signal];
    }

    /**
     * Returns all read samples of all signals.
     * @return
     */
    public static double[][] getAllData(){
        return data;
    }

    public static int getCurrentSampleSize(){
        return currentSampleSize;
    }

    public static void setCurrentSampleSize(int sampleSize){
        currentSampleSize = sampleSize;
        Buffer.readFile(curFile, sampleSize);
    }

    public static double getRecordDuration() {
        return recordDuration;
    }

    /**
     * @return the numberOfSamples
     */
    public static double getNumberOfSamples() {
        return numberOfSamples;
    }

    /**
     * @return the timePerSample
     */
    public static double getTimePerSample() {
        return timePerSample;
    }
}
